package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by utsabban on 3/2/14.
 */
public class Movie {
    private String movieName;
    private String directorName;
    private Integer yearOfRelease;
    private Integer rating;
    private Integer currentQuantity;
    private final Integer maxQuantity;
    private List<String> borrowerList;

    public Movie(String movieName, String directorName, Integer yearOfRelease, Integer rating,Integer currentQuantity,Integer maxQuantity) {
        this.movieName = movieName;
        this.directorName = directorName;
        this.yearOfRelease = yearOfRelease;
        this.rating = rating;
        this.currentQuantity = currentQuantity;
        this.maxQuantity = maxQuantity;
        borrowerList = new ArrayList<String>();
    }


    public String displayMovieInformation() {
        return movieName+" "+directorName+" "+yearOfRelease+" "+(rating==null?"Unrated":""+rating);
    }

    @Override
    public String toString() {
        return "Movie{" +
                "movieName='" + getMovieName() + '\'' +
                ", directorName='" + directorName + '\'' +
                ", yearOfRelease=" + yearOfRelease +
                ", rating=" + rating +
                ", currentQuantity=" + getCurrentQuantity() +
                ", maxQuantity=" + maxQuantity +
                ", borrowerList=" + borrowerList +
                '}';
    }

    public String getMovieName() { return movieName; }

    public Integer getCurrentQuantity() { return currentQuantity; }

    public boolean movieCheckout(String movieToCheckout,String borrowerCustomerNumber)
    {
        if(!movieName.equals(movieToCheckout))
            return false;
        if(currentQuantity>0)
            currentQuantity--;
        else
            return false;
        borrowerList.add(borrowerCustomerNumber);
        return true;
    }

    public boolean movieReturn(String movieToReturn,String borrowerCustomerNumber)
    {
        if(!movieName.equals(movieToReturn))
            return false;
        if(borrowerList.contains(borrowerCustomerNumber) && currentQuantity<maxQuantity)
            currentQuantity++;
        else
            return false;
        borrowerList.remove(borrowerCustomerNumber);
        return true;
    }

    public List<String> returnBorrowers()
    {
        return borrowerList;
    }
}
